﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;

namespace Utils
{
    public class Encrypt
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="valueString"></param>
        /// <returns></returns>
        public static string MD5Encrypt(string valueString)
        {
            string ret = String.Empty;
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(valueString);
            data = md5Hasher.ComputeHash(data);
            for (int i = 0; i < data.Length; i++)
            {
                ret += data[i].ToString("x2").ToLower();
            }
            return ret;

        }
        public static byte[] MD5Encrypt(byte[] sourceToEncrypt)
        {
            Byte[] encodedBytes;
            MD5 md5;
            md5 = new MD5CryptoServiceProvider();
            encodedBytes = md5.ComputeHash(sourceToEncrypt);
            return encodedBytes;
        }
    }
}
